package com.shqcjd.preinstallglass.api;

import com.lzy.okgo.OkGo;
import com.lzy.okrx2.adapter.ObservableBody;
import com.shqcjd.preinstallglass.helper.JsonConvert;
import com.shqcjd.preinstallglass.model.pojo.AbnormalBean;
import com.shqcjd.preinstallglass.model.pojo.EquipmentAbnormalBean;
import com.shqcjd.preinstallglass.model.pojo.EquipmentGroupBean;
import com.shqcjd.preinstallglass.model.pojo.EquipmentInspectionBean;
import com.shqcjd.preinstallglass.model.pojo.ExpertListBean;
import com.shqcjd.preinstallglass.model.pojo.IntentEquipmentBean;
import com.shqcjd.preinstallglass.model.pojo.FileBean;
import com.shqcjd.preinstallglass.model.pojo.LoginBean;
import com.shqcjd.preinstallglass.model.ResponseData;
import com.shqcjd.preinstallglass.model.pojo.RouteListBean;
import com.shqcjd.preinstallglass.model.pojo.TaskCodeBean;

import org.json.JSONObject;

import java.util.List;

import java.io.File;

import io.reactivex.Observable;

/**
 * Created by sy on 2019/3/14.
 */

public class ApiService {
    public static Observable<ResponseData<LoginBean>> login(JSONObject loginBean) {
        return OkGo.<ResponseData<LoginBean>>post(HttpUrl.LOGIN)
                .upJson(loginBean)
                .converter(new JsonConvert<ResponseData<LoginBean>>(){})
                .adapt(new ObservableBody<ResponseData<LoginBean>>());

    }

    public static Observable<ResponseData<EquipmentAbnormalBean>> equipmentAbnormalHttp(int tId, int eId) {
        return OkGo.<ResponseData<EquipmentAbnormalBean>>get(HttpUrl.EQUIPMENT_ABNORMAL+"?equipment_id="+eId+"&task_id="+tId)
                .converter(new JsonConvert<ResponseData<EquipmentAbnormalBean>>(){})
                .adapt(new ObservableBody<ResponseData<EquipmentAbnormalBean>>());
    }

    public static Observable<ResponseData<EquipmentGroupBean>> equipmentGroupHttp(int tId, String kks) {
        return OkGo.<ResponseData<EquipmentGroupBean>>get(HttpUrl.EQUIPMENT_GROUP+"?kks="+kks+"&task_id="+tId)
                .converter(new JsonConvert<ResponseData<EquipmentGroupBean>>(){})
                .adapt(new ObservableBody<ResponseData<EquipmentGroupBean>>());
    }

    public static Observable<ResponseData<EquipmentInspectionBean>> equipmentInspectionHttp(int task_id, String kks) {
        return OkGo.<ResponseData<EquipmentInspectionBean>>get(HttpUrl.EQUIPMENT_INSPECTION+"?task_id="+task_id+"&kks="+kks)
                .converter(new JsonConvert<ResponseData<EquipmentInspectionBean>>(){})
                .adapt(new ObservableBody<ResponseData<EquipmentInspectionBean>>());
    }

    public static Observable<ResponseData<RouteListBean>> routeListHttp(JSONObject routeBean) {
        return OkGo.<ResponseData<RouteListBean>>post(HttpUrl.ROUTE_LIST)
                .upJson(routeBean)
                .converter(new JsonConvert<ResponseData<RouteListBean>>(){})
                .adapt(new ObservableBody<ResponseData<RouteListBean>>());

    }

    public static Observable<ResponseData<ExpertListBean>> getExpertList(JSONObject parameter){
        return OkGo.<ResponseData<ExpertListBean>>post(HttpUrl.GET_EXPERT_LIST)
                .upJson(parameter)
                .converter(new JsonConvert<ResponseData<ExpertListBean>>(){})
                .adapt(new ObservableBody<ResponseData<ExpertListBean>>());

    }

    public static Observable<ResponseData> getGroupTrue(int task_id, int equipment_id) {
        return OkGo.<ResponseData>get(HttpUrl.GET_GROUP_TRUE+"?task_id="+task_id+"&equipment_id="+equipment_id)
                .converter(new JsonConvert<ResponseData>(){})
                .adapt(new ObservableBody<ResponseData>());
    }

    public static Observable<ResponseData> openOrCloseSwitchHttp(String kks) {
        return OkGo.<ResponseData>get(HttpUrl.OPEN_OR_CLOSE_EQUIPMENT+"?kks="+kks)
                .converter(new JsonConvert<ResponseData>(){})
                .adapt(new ObservableBody<ResponseData>());
    }

    /**
     * 独立设备巡检页 点击读取按钮的接口
     * @return
     */
    public static Observable<ResponseData<String>> equipmentInspectionButtonHttp(String url, int equipmentId, String type, int equipmentPartItemId) {
        return OkGo.<ResponseData<String>>get(url+"?equipmentId="+equipmentId+"&type="+type+"&equipmentPartItemId="+equipmentPartItemId)
                .converter(new JsonConvert<ResponseData<String>>(){})
                .adapt(new ObservableBody<ResponseData<String>>());
    }

    public static Observable<ResponseData<Integer>> putCheckResultHttp(JSONObject jsonObject) {
        return OkGo.<ResponseData<Integer>>post(HttpUrl.PUT_CHECK_RESULT)
                .upJson(jsonObject)
                .converter(new JsonConvert<ResponseData<Integer>>(){})
                .adapt(new ObservableBody<ResponseData<Integer>>());
    }

    public static Observable<ResponseData<IntentEquipmentBean>> intentEquipmentHttp(String kks, int task_id) {
        return OkGo.<ResponseData<IntentEquipmentBean>>get(HttpUrl.INTENT_EQUIPMENT+"?kks="+kks+"&task_id="+task_id)
                .converter(new JsonConvert<ResponseData<IntentEquipmentBean>>(){})
                .adapt(new ObservableBody<ResponseData<IntentEquipmentBean>>());
    }

    public static Observable<ResponseData<List<String>>> uploadMultiImg(List<File> files) {
        return OkGo.<ResponseData<List<String>>>post(HttpUrl.UPLOAD_MULTI_IMG)
                .addFileParams("file", files)
                .converter(new JsonConvert<ResponseData<List<String>>>(){})
                .adapt(new ObservableBody<ResponseData<List<String>>>());
    }

    public static Observable<ResponseData<String>> putCheckException(String jsonObject) {
        return OkGo.<ResponseData<String>>post(HttpUrl.PUT_CHECK_EXCEPTION)
                .upJson(jsonObject)
                .converter(new JsonConvert<ResponseData<String>>(){})
                .adapt(new ObservableBody<ResponseData<String>>());
    }

    public static Observable<ResponseData<String>> createGuide(JSONObject jsonObject) {
        return OkGo.<ResponseData<String>>post(HttpUrl.CREATE_GUIDE)
                .upJson(jsonObject)
                .converter(new JsonConvert<ResponseData<String>>(){})
                .adapt(new ObservableBody<ResponseData<String>>());
    }

    public static Observable<ResponseData> handleGuide(JSONObject jsonObject) {
        return OkGo.<ResponseData>post(HttpUrl.HANDLE_GUIDE)
                .upJson(jsonObject)
                .converter(new JsonConvert<ResponseData>(){})
                .adapt(new ObservableBody<ResponseData>());
    }

    public static Observable<ResponseData<List<FileBean>>> getFileList(String roomId) {
        return OkGo.<ResponseData<List<FileBean>>>get(HttpUrl.GET_FILE_LIST+roomId)
                .converter(new JsonConvert<ResponseData<List<FileBean>>>(){})
                .adapt(new ObservableBody<ResponseData<List<FileBean>>>());
    }

    public static Observable<ResponseData<String>> word2pf(String url) {
        return OkGo.<ResponseData<String>>post(HttpUrl.WORD_2_PDF)
                .params("url",url)
                .converter(new JsonConvert<ResponseData<String>>(){})
                .adapt(new ObservableBody<ResponseData<String>>());
    }

    public static Observable<ResponseData<TaskCodeBean>> getRandomTask() {
        return OkGo.<ResponseData<TaskCodeBean>>get(HttpUrl.CREATE_RANDOM_TASK)
                .converter(new JsonConvert<ResponseData<TaskCodeBean>>(){})
                .adapt(new ObservableBody<ResponseData<TaskCodeBean>>());
    }

    public static Observable<ResponseData<AbnormalBean>> getAbnormalInfo(int task_id, int equipment_id, int equipment_part_item_id, String value) {
        return OkGo.<ResponseData<AbnormalBean>>get(HttpUrl.GET_ABNORMAL_INFO+"?task_id="+task_id+"&equipment_id="+equipment_id+"&equipment_part_item_id="+equipment_part_item_id+"&value="+value)
                .converter(new JsonConvert<ResponseData<AbnormalBean>>(){})
                .adapt(new ObservableBody<ResponseData<AbnormalBean>>());
    }
}
